package com.avic.system.controller.feign;

import com.avic.system.common.util.AssertUtil;
import com.avic.system.common.util.lang.ServiceCallBack;
import com.avic.system.controller.AbstractFacadeImpl;
import com.avic.system.controller.request.CreateSystemLogReq;
import com.avic.system.controller.result.CreateSystemLogRes;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/system/log/feign")
public class SystemLogFeign extends AbstractFacadeImpl {

    @PostMapping
    public CreateSystemLogRes createSystemLog(@RequestBody CreateSystemLogReq createSystemLogReq) {
        log.info("新增系统日志--createSystemLog");
        final CreateSystemLogRes result = new CreateSystemLogRes();
        return serviceExecuteTemplate.executeService(result, new ServiceCallBack() {
            @Override
            public void check() throws Exception {
                AssertUtil.isNotBlank(createSystemLogReq.getUserId(), "操作人不能为空");
                AssertUtil.isNotBlank(createSystemLogReq.getLogDetail(), "操作日志不能为空");

            }

            @Override
            public void doService() throws Exception {
                result.setLogId(
                        systemLogService.createSystemLog(createSystemLogReq.getLogDetail(), createSystemLogReq.getUserId()));
                result.setSuccess(true);
            }
        });
    }
}
